import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
import nestedRouter from './modules/nested'
/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
  path: '/login',
  component: () => import('@/views/login/index'),
  hidden: true
},

{
  path: '/404',
  component: () => import('@/views/404'),
  hidden: true
},

{
  path: '/',
  component: Layout,
  redirect: '/index',
  children: [{
    path: 'index',
    name: 'index',
    component: () => import('@/views/index/index'),
    meta: {
      title: '首页',
      icon: 'component'
    }
  }]
},
{
  path: '/system',
  component: Layout,
  redirect: '/system',
  name: 'system',
  meta: {
    title: '权限管理(开发中)',
    icon: 'lock'
  },
  children: [
  //   {
  //   path: 'role',
  //   component: () => import('@/views/system/role'),
  //   meta: {
  //     title: '角色列表'
  //   }
  // },
    {
      path: 'user',
      component: () => import('@/views/system/user'),
      meta: {
        title: '用户列表'
      }
    }
  ]
},
{
  path: '/driver',
  component: Layout,
  redirect: '/driver',
  name: 'driver',
  meta: {
    title: '司机管理',
    icon: 'people'
  },
  children: [{
    path: 'driver',
    component: () => import('@/views/driver/list'),
    meta: {
      title: '司机列表'
    }
  }, {
    path: 'menu2',
    component: () => import('@/views/driver/comment'),
    meta: {
      title: '评价列表'
    }
  }]
},
{
  path: '/owner',
  component: Layout,
  redirect: '/owner',
  name: 'owner',
  meta: {
    title: '货主管理',
    icon: 'user'
  },
  children: [{
    path: 'dashboard11',
    component: () => import('@/views/owner/list'),
    meta: {
      title: '货主列表'
    }
  }]
},
{
  path: '/order',
  component: Layout,
  redirect: '/order',
  name: 'order',
  meta: {
    title: '订单管理',
    icon: 'list'
  },
  children: [{
    path: 'list',
    component: () => import('@/views/order/list'),
    meta: {
      title: '订单列表'
    }
  }, {
    path: 'set',
    component: () => import('@/views/order/set'),
    meta: {
      title: '订单配置'
    }
  }]
},
{
  path: '/car',
  component: Layout,
  redirect: '/car',
  name: 'car',
  meta: {
    title: '车辆管理',
    icon: 'dashboard'
  },
  children: [{
    path: 'dashboard1',
    component: () => import('@/views/car/list'),
    meta: {
      title: '车辆列表'
    }
  },
  // {
  //   path: 'dashboard2',
  //   component: () => import('@/views/dashboard/index'),
  //   meta: {
  //     title: '停用列表'
  //   }
  // },
  {
    path: 'dashboard3',
    component: () => import('@/views/car/setting'),
    meta: {
      title: '车辆配置'
    }
  }]
},
nestedRouter,

// {
//   path: '/audit',
//   component: Layout,
//   redirect: '/audit',
//   name: 'audit',
//   meta: {
//     title: '审核管理',
//     icon: 'edit'
//   },
//   children: [{
//     path: 'owner',
//     component: () => import('@/views/audit/owner'),
//     meta: {
//       title: '货主审核'
//     }
//     // children: [{
//     //   path: 'idImg',
//     //   component: () => import('@/views/audit/owner/id'),
//     //   meta: {
//     //     title: '身份认证'
//     //   }
//     // }, {
//     //   path: 'company',
//     //   component: () => import('@/views/audit/owner/company'),
//     //   meta: {
//     //     title: '公司认证'
//     //   }
//     // }
//     // ]
//   },

//   {
//     path: 'driver',
//     // component: () => import('@/views/audit/driver'),
//     meta: {
//       title: '司机审核'
//     },
//     children: [{
//       path: 'id',
//       component: () => import('@/views/audit/driver/id'),
//       meta: {
//         title: '身份认证'
//       }
//     }, {
//       path: 'company',
//       component: () => import('@/views/audit/driver/company'),
//       meta: {
//         title: '公司认证'
//       }
//     }, {
//       path: 'licence',
//       component: () => import('@/views/audit/driver/licence'),
//       meta: {
//         title: '驾驶证行驶证认证'
//       }
//     }
//     ]
//   }, {
//     path: 'car',
//     component: () => import('@/views/audit/car'),
//     meta: {
//       title: '车辆审核'
//     }
//   }, {
//     path: 'finance',
//     component: () => import('@/views/audit/finance'),
//     meta: {
//       title: '财务审核'
//     }
//   }]
// },
{
  path: '/message',
  component: Layout,
  redirect: '/index',
  name: 'message',
  meta: {
    title: '消息管理',
    icon: 'message'
  },
  children: [{
    path: 'dashboard1',
    component: () => import('@/views/message/sendxcxMsg'),
    meta: {
      title: '小程序内消息'
    }
  }, {
    path: 'dashboard2',
    component: () => import('@/views/index/index'),
    meta: {
      title: '短信消息(暂停)'
    }
  }]
},
{
  path: '/platform',
  component: Layout,
  redirect: '/index',
  name: 'platform',
  meta: {
    title: '平台运营',
    icon: 'example'
  },
  children: [
    {
      path: 'withdraw',
      component: () => import('@/views/system/servicemoney'),
      meta: {
        title: '提现手续费'
      }
    },
    {
    path: 'banner',
    component: () => import('@/views/system/banner'),
    meta: {
      title: 'banner'
    }
  },
  {
    path: 'dashboard2',
    component: () => import('@/views/index/index'),
    meta: {
      title: '运费险(暂停)'
    }
  }, {
    path: 'dashboard3',
    component: () => import('@/views/index/index'),
    meta: {
      title: '放空险(暂停)'
    }
  }
  ]
},
{
  path: '/invo',
  component: Layout,
  redirect: '/index',
  name: 'invo',
  meta: {
    title: '发票管理',
    icon: 'message'
  },
  children: [{
    path: 'invoice',
    component: () => import('@/views/invoice/invoice'),
    meta: {
      title: '发票管理'
    }
  }
  // {
  //   path: 'invoice',
  //   component: () => import('@/views/invoice/invoice'),
  //   meta: {
  //     title: '数据列表'
  //   }
  // }
]
},
// {
//   path: '/data',
//   component: Layout,
//   redirect: '/index',
//   children: [{
//     path: 'index',
//     name: 'data',
//     component: () => import('@/views/index/index'),
//     meta: {
//       title: '数据展示',
//       icon: 'chart'
//     }
//   }]
// },
// {
//   path: '/1',
//   component: Layout,
//   redirect: '/index',
//   children: [{
//     path: 'index',
//     name: 'Dxashboard',
//     component: () => import('@/views/index/index'),
//     meta: {
//       title: 'Dsashboard',
//       icon: 'index'
//     }
//   }]
// },

// {
//   path: '/example',
//   component: Layout,
//   redirect: '/example/table',
//   name: 'Example',
//   meta: {
//     title: 'Example',
//     icon: 'example'
//   },
//   children: [{
//     path: 'table',
//     name: 'Table',
//     component: () => import('@/views/table/index'),
//     meta: {
//       title: 'Table',
//       icon: 'table'
//     }
//   },
//   {
//     path: 'tree',
//     name: 'Tree',
//     component: () => import('@/views/tree/index'),
//     meta: {
//       title: 'Tree',
//       icon: 'tree'
//     }
//   }
//   ]
// },

// {
//   path: '/form',
//   component: Layout,
//   children: [{
//     path: 'index',
//     name: 'Form',
//     component: () => import('@/views/form/index'),
//     meta: {
//       title: 'Form',
//       icon: 'form'
//     }
//   }]
// },

// {
//   path: '/nested',
//   component: Layout,
//   redirect: '/nested/menu1',
//   name: 'Nested',
//   meta: {
//     title: 'Nested',
//     icon: 'nested'
//   },
//   children: [{
//     path: 'menu1',
//     component: () => import('@/views/nested/menu1/index'), // Parent router-view
//     name: 'Menu1',
//     meta: {
//       title: 'Menu1'
//     },
//     children: [{
//       path: 'menu1-1',
//       component: () => import('@/views/nested/menu1/menu1-1'),
//       name: 'Menu1-1',
//       meta: {
//         title: 'Menu1-1'
//       }
//     },
//     {
//       path: 'menu1-2',
//       component: () => import('@/views/nested/menu1/menu1-2'),
//       name: 'Menu1-2',
//       meta: {
//         title: 'Menu1-2'
//       },
//       children: [{
//         path: 'menu1-2-1',
//         component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
//         name: 'Menu1-2-1',
//         meta: {
//           title: 'Menu1-2-1'
//         }
//       },
//       {
//         path: 'menu1-2-2',
//         component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
//         name: 'Menu1-2-2',
//         meta: {
//           title: 'Menu1-2-2'
//         }
//       }
//       ]
//     },
//     {
//       path: 'menu1-3',
//       component: () => import('@/views/nested/menu1/menu1-3'),
//       name: 'Menu1-3',
//       meta: {
//         title: 'Menu1-3'
//       }
//     }
//     ]
//   },
//   {
//     path: 'menu2',
//     component: () => import('@/views/nested/menu2/index'),
//     meta: {
//       title: 'menu2'
//     }
//   }
//   ]
// },

// {
//   path: 'external-link',
//   component: Layout,
//   children: [{
//     path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
//     meta: {
//       title: 'External Link',
//       icon: 'link'
//     }
//   }
// ]
// },

// 404 page must be placed at the end !!!
{
  path: '*',
  redirect: '/404',
  hidden: true
}
]

const createRouter = () => new Router({
  base: '/admin/',
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
